package org.game;

import java.awt.event.ActionEvent;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;

public class MenuAction extends AbstractAction  {

	private Puzzle puzzle;
	ResourceBundle messages = ResourceBundle.getBundle("org.config.Messages", Locale.getDefault());
	public MenuAction(Object puzzle, String string) {
		super(string);
		this.puzzle = (Puzzle)puzzle;
	}

	public MenuAction(Object puzzle, String nomImg, ImageIcon ic)
    {
        super(nomImg,ic);
        this.puzzle = (Puzzle)puzzle;
    }

    @Override
	public void actionPerformed(ActionEvent e) {
	    final String action = e.getActionCommand();
	    final Object composant = e.getSource();
      new Thread(new Runnable() {
      public void run() {
          if (action.equals("newGame")){
              puzzle.initDraw();
          }          
          if (action.equals("lEasy")){
              puzzle.setNbCols(4);
              puzzle.setNbRows(3);
          }
          if (action.equals("lMedium")){
              puzzle.setNbCols(6);
              puzzle.setNbRows(4);
          }
          if (action.equals("lHard")){
              puzzle.setNbCols(12);
              puzzle.setNbRows(8);
          } 
          if (action.indexOf(".")>0){
              puzzle.setNomImage(action);
          }
          if (action.equals("actCheckBloc")){
        	  if (((JCheckBoxMenuItem)composant).isSelected()){
              	puzzle.setFixImage(true);
        	  }else{
        		  puzzle.setFixImage(false);
        	  }
          }              
      }
  }).start();	    
	
		
	}
//	public void actionPerformed(ActionEvent e) {
//		  new Thread(new Runnable() {
//		      public void run() {
//		        String text = readHugeFile();
//		        textArea.setText(text);
//		      }
//		  }).start();
//		}

}
